package com.dw.dwdzcommerce.view.operate;

import com.dw.dwdzcommerce.R;
import com.dw.dwdzcommerce.test.TestFragmentMap;
import com.dw.dwdzcommerce.view.mainContent.mainActionBar.MainContentActionBarFragment;
import com.dw.dwdzcommerce.view.mainContent.mainActionBar.MainContentActionBarFragment.OnMainContentActionBarClickListener;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

public class OperateActionBarLayout {
	private MainContentActionBarFragment mMainContentActionBarFragment;
	private TestFragmentMap maptest;
	private OperateActivity mActivity;

	public void initModule(OperateActivity activity) {
		initModule(activity,null);
	}
	
	public void initModule(OperateActivity activity,OnMainContentActionBarClickListener listener){
		mActivity = activity;
		initFragment(listener);
	}
	
	private void initFragment(OnMainContentActionBarClickListener listener) {
		mMainContentActionBarFragment = new MainContentActionBarFragment();
		mMainContentActionBarFragment.setmListener(listener);
		maptest = new TestFragmentMap();
		addFragment(mMainContentActionBarFragment);
		addFragment(maptest);
		
		
	}

	private void addFragment(Fragment fragment) {
		FragmentTransaction transaction = mActivity.getSupportFragmentManager().beginTransaction();
		boolean added = fragment.isAdded();
		if (added) {
			return;
		}
		transaction.add(R.id.activity_operate_actionbar_container, fragment);
		transaction.commit();
	}

	public void selectMainActionBarFragment() {
		showFragment(mMainContentActionBarFragment);
	}

	public void selectMapActionBarFragment() {
		showFragment(maptest);
	}

	public void selectMineActionBarFragment() {
		showFragment(mMainContentActionBarFragment);
	}

	private void showFragment(Fragment fragment) {
		FragmentTransaction transaction = mActivity.getSupportFragmentManager().beginTransaction();
		hideAll(transaction);
		transaction.show(fragment);
		transaction.commit();
	}

	private void hideAll(FragmentTransaction transaction) {
		transaction.hide(mMainContentActionBarFragment);
		transaction.hide(maptest);

	}

	public interface OnActionBarDataCallback {

	}

}
